﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using IiiToolkitMain.Common;

namespace IiiToolkitMain
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new ThreadExceptionEventHandler(Error);

            //args = new[] { "ewind://video?appkey=8cf007e034894bc2b9520fd394926362&secret=95dd95175dbeae012a2894a643d1bcf5&devicederial=585171107&channelno=1" };
            if (args == null || args.Length < 1)
            {
                //检查注册表有没有自定义的URL协议
                MessageBox.Show("检查注册表有没有自定义的URL协议");
            }
            else
            {
                var url = args[0];
                
                var model = UrlParser.ParseUrl(url);
                switch (model.Type)
                {
                    case AppType.Video:
                    case AppType.InnerVideo:
                        Application.Run(new Video(model));
                        break;
                    case AppType.Other:
                        MessageBox.Show("暂未支持此类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                    case AppType.Error:
                        MessageBox.Show("您传入的参数不正确!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                }
            }
        }

        private static void Error(object sender, ThreadExceptionEventArgs threadExceptionEventArgs)
        {
            MessageBox.Show(threadExceptionEventArgs.Exception.Message);
        }
    }
}
